
@extends('admin.common.common')

@section('head')
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <link rel="stylesheet" href="/admin/static/h-ui.admin/css/bootstrap.min.css">
@endsection



@section('body')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 节点中心 <span class="c-gray en">&gt;</span> 节点管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="pd-20">
        <form action="{{route('admin.role.index')}}">
            <div class="text-c">节点管理：
                <input type="text" class="input-text" style="width:250px" placeholder="输入节点名称" value="{{Request()->get('keyword')}}" name="keyword">
                <button type="submit" class="btn btn-success" id="" name=""><i class="icon-search"></i> 搜节点</button>
            </div>
        </form>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
    <span class="l">
        <a href="javascript:;" class="btn btn-danger radius deleteAll"><i class="icon-trash"></i> 批量删除</a>
    <a href="{{route('admin.node.create')}}" class="btn btn-primary radius"><i class="icon-plus"></i> 添加节点</a></span>
            <span class="r">共有数据：<strong></strong> 条</span>
        </div>
        <table class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>
            <tr class="text-c">
                <th width="25"><input type="checkbox" name="checkall" value=""></th>
                <th width="80">ID</th>
                <th width="100">节点名</th>
                <th width="100">路由别名</th>
                <th width="100">父级id</th>
                <th width="130">加入时间</th>
                <th width="100">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $key=>$val)
                <tr class="text-c">
                    @if(auth()->id()!=$val->id)
                        @if($val->deleted_at)
                            <td></td>
                        @else
                            <td><input type="checkbox" value="{{$val->id}}" name="ids[]"></td>
                        @endif

                    @else
                        <td></td>
                    @endif

                    <td>{{$val->id}}</td>
                    <td style="text-align: left">{{$val->html}}{{$val->name}}</td>
                    <td>{{$val->route_name}}</td>
                    <td>{{$val->pid}}</td>
                    <td>{{$val->created_at}}</td>
                    <td class="f-14 user-manage" style="width: 200px">
                        <a title="编辑" href="{{route('admin.node.edit',$val)}}" class="btn btn-success" style="text-decoration:none"><i class="icon-edit">编辑</i></a>
                        @if(auth()->id()!=$val->id)
                            @if($val->deleted_at)
                                <a title="恢复" href="javascript:;" data-id="{{$val->id}}"  class="btn btn-warning restorydel" style="text-decoration:none;color: black"><i class="icon-trash">恢复</i></a>
                            @else
                                <a title="删除" href="{{route('admin.node.destroy',$val)}}"  class="btn btn-danger del" style="text-decoration:none"><i class="icon-trash">删除</i></a>
                            @endif
                        @endif
                    </td>
                </tr>

            @endforeach
            </tbody>
        </table>

        <div id="pageNav" class="pageNav"></div>
    </div>

@endsection


@section('js')
    <script src="/admin/static/h-ui.admin/js/layer/layer.js"></script>
    <script>
        //删除用户
        $('.del').click(function (obj) {
            let url = $(this).attr('href');
            let _that = $(this)
            $.ajax({
                data: {
                    _token:"{{csrf_token()}}"
                },
                url:url,
                dataType:"json",
                type:"delete",
                success:function (res) {
                    if(res.error_code==0){
                        layer.msg(res.msg,{ico:2,time:2000},function () {
                            // _that.parents('tr').remove()
                            history.go(0)
                        })
                    }else{
                        layer.msg(res.msg,{icon:5,time: 2000})
                    }
                }
            })
            return false;
        })

        //恢复删除用户
        $('.restorydel').click(function (obj) {
            let href = $(this).attr('href')

            $.ajax({
                url: href,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                dataType: "json",
                type: "GET",
                success:function (res) {
                    if(res.status==1){
                        layer.msg(res.msg,{icon: 1,time:2000},function () {
                            history.go(0);
                        })
                    }else{
                        layer.msg(res.msg)
                    }
                }

            })

            return false;
        })

        //全选全不选

        $("input[name='checkall']").click(function () {
            $("input[name='ids[]']").prop('checked',$("input[name='checkall']").prop('checked'))
        })

        //批量删除
        $('.deleteAll').click(function () {
            let ids = []
            let id = $("input[name='ids[]']:checked")
            $.each(id,function (key,val) {
                ids.push(val.value)
            })
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url:"",
                data:{id:ids},
                dataType:"json",
                type:"post",
                success:function (res) {
                    if(res.status==1){
                        layer.msg(res.msg,{ico:2,time:2000},function () {
                            // _that.parents('tr').remove()
                            history.go(0)
                        })
                    }else{
                        layer.msg(res.msg,{icon:5,time: 2000})
                    }
                }
            })
        })
    </script>

@endsection
